home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
DEMO_VGA
/
PLOTFRAC.LZH
/
PLOTFRAC.C
< prev
next >
Wrap
Text File
|
1987-10-26
|
34KB
|
1,003 lines
/*
P L O T F R A C . C
VERSION : 3.0
*/
#include <vcstdio.h>
#include <conio.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <dos.h>
#include <process.h>
#include <string.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <float.h>
#include "grafix.h" /* My own Int. 10h driven graphics routines */
extern void set_plot(int);
extern void plot_fractal (char *, int);
extern void restore_picture (void);
extern long factorial (int);
extern int build_fctn (int);
extern double calc_nx (double, double);
extern double calc_ny (double, double);
extern double pow_r (double, int);
struct stat pic_buf;
int result = 0, graf_mode = 4, mycolor = 0, n_x = 0, n_y = 0, hr_mode = 6,
M = 100, K = 200, v_lin_count = 0, v_lin_max = 319, h_lin_count = 0,
max_row = 199, degree = 0, wno, wno1, wno2, wno3, errwno;
int real_exp[51], imag_exp[51];
long konst[51];
double x[201], y[201];
double x_max = 0, y_max = 0, x_min = 0, y_min = 0, p = 0, q = 0, p_max = 0,
p_min = 0, a = 0, b = 0, c = 0, delt_y= 0, delt_x= 0, delt_p = 0,
delt_q = 0, r = 0, q_min = 0, q_max = 0;
main()
{
register int ii;
int alldone, i, j, iresult;
double d_i;
char *result, line[80], title[80];
for (ii=0;ii<51;ii++) {
real_exp[ii] = 0;
imag_exp[ii] = 0;
konst[ii] = 0;
}
for (ii=0;ii<201;ii++) {
x[ii] = 0;
y[ii] = 0;
}
vcstart(CLRSCRN);
empty(title, 80);
sprintf(title,"PLOTFRAC V4.0 25-Oct-87 by Ron Merts");
if ((wno = wxopen(0,0,24,79,title,
BORDER+BD1+CURSOR+ACTIVE+CENTER,24,80)) == -1)
terror("main(): Error opening main window (WNO).\n");
wselect(wno);
h_lin_count = 0;
alldone = 0;
erase();
wselect(wno);
woff();
atsay(0,26,"Welcome to PLOTFRAC V4.0");
atsay(1,24,"Written By Ronald F. Merts");
won();
while (!alldone) {
degree = 0;
if ((wno1 = wxopen(8,0,16,79,"Main Selection Menu",
BORDER+BD2+CURSOR+CENTER,24,80)) == -1)
terror("main(): Error opening Main Selection Menu window (WNO1)\n");
wselect(wno1);
empty(line, 80);
atsay(0,0,"Do you want to:");
atsay(1,0," 1 - Plot a Julia Set");
atsay(2,0," 2 - Plot a Mandelbrot Set");
atsay(3,0," 3 - Load a previous picture");
atsay(4,0," 4 - DIRectory of .PIC files");
atsay(5,0," Q - Quit to DOS");
atsayget(6,0,"Enter your choice (1, 2, 3, 4 or Q): ",line,"X");
wshow(wno1);
readgets();
switch (line[0]) {
case '1': /* Plot a Julia-Set */
wselect(wno);
wshow(wno);
wclose(wno1);
if ((wno1 == wxopen(8,0,12,79,"Picture File Selection",
BORDER+BD2+CURSOR+CENTER,10,80)) == -1)
terror("main(): Error opening Picture file selection window (WNO1)\n");
wselect(wno1);
empty(line, 80);
atsayget(1,0,"Enter filename for picture SAVE: ", line,
"XXXXXXXX.XXX");
wshow(wno1);
readgets();
if (isblank(line)){
wselect(wno);
wshow(wno);
wclose(wno1);
break;
}
whide(wno);
set_plot(1);
plot_fractal(result,1);
wshow(wno);
break;
case '2': /* Plot a Mendlebrot Graph */
wselect(wno);
wshow(wno);
wclose(wno1);
if ((wno1 == wxopen(8,0,12,79,"Picture File Selection",
BORDER+BD2+CURSOR+CENTER,10,80)) == -1)
terror("main(): Error opening Picture file selection window (WNO1)\n");
wselect(wno1);
empty(line, 80);
atsayget(1,0,"Enter filename for picture SAVE: ", line,
"XXXXXXXX.XXX");
wshow(wno1);
readgets();
if (isblank(line)){
wselect(wno);
wshow(wno);
wclose(wno1);
break;
}
whide(wno);
set_plot(2);
plot_fractal(result,2);
wshow(wno);
break;
case '3': /* Restore a previous picture */
wselect(wno);
wshow(wno);
wclose(wno1);
whide(wno);
restore_picture();
wshow(wno);
break;
case '4': /* Directory of .PIC files */
wselect(wno);
wshow(wno);
wclose(wno1);
whide(wno);
i = system("DIR *.PIC");
printf("Press any key to continue . . . ");
iresult = getone();
wshow(wno1);
break;
case 'Q':
case 'q': /* Quit to DOS */
wclose(wno1);
wclose(wno);
vcend(CLOSE);
printf("Good Bye...\n");
alldone = 1;
break;
default: /* Difficulty typing 'eh? */
if ((errwno == wxopen(22,0,24,79,"Error Message",
BORDER+BD2+CURSOR+CENTER+ACTIVE,5,80)) == -1)
terror("main(): Error opening Error Message window (ERRWNO)\n");
wselect(errwno);
atsay(0,0,"Invalid Command....Please choose 1, 2, 3, 4 or Q");
for (ii=0;ii<=2500;ii++)
d_i = i * 1.01;
wselect(wno);
whide(errwno);
wclose(errwno);
wclose(wno1);
break;
} /* End of SWITCH */
} /* End of WHILE */
} /* End of MAIN */
void set_plot(frac_mode)
int frac_mode;
{
int x_y_chosen, p_q_chosen, m_k_chosen, mode_chosen, deg_chosen, gr_m;
char line[80], *li_result, title[80], inp1[80], inp2[80],
inp3[80], inp4[80];
v_lin_count = 0;
x_y_chosen = 0;
p_q_chosen = 0;
m_k_chosen = 0;
mode_chosen = 0;
deg_chosen = 0;
if (frac_mode == 1)
sprintf(title, "SETUP for a Julia Set plot");
else if (frac_mode == 2)
sprintf(title, "SETUP for a Mandelbrot Set plot");
if ((wno1 = wxopen(0,0,22,79,title,
ACTIVE+BORDER+BD2+SCROLL+CURSOR+CENTER,24,80)) == -1)
terror("set_plot(): Error opening main selection(s) window (WNO1)\n");
wselect(wno1);
while (!deg_chosen) {
sprintf(title,"Polynomial Degree Selection");
if ((wno2 = wxopen(5,0,9,79,title,
ACTIVE+BORDER+BD2+SCROLL+CURSOR+CENTER,24,80)) == -1)
terror("set_plot(): Error opening Degree Selection window (WNO2)\n");
wselect(wno2);
erase();
empty(inp1, 80);
atsayget(1, 0, "What degree is the polynomial (2-50)? ", inp1, "##");
readgets();
wclose(wno2);
degree = atoi(inp1);
if (degree >=2 && degree <= 50) {
if ((wno2 = wxopen(5,0,11,79,"Confirm (Y/N)",
ACTIVE+BORDER+BD1+SCROLL+CURSOR+CENTER,3,80)) == -1)
terror("set_plot(): Error opening confirmation window.\n");
wselect(wno2);
sprintf(line,"Feedback polynomial is F(z)= z^%d + c.",degree);
atsay(0,0,line);
empty(inp2, 80);
atsayget(2, 0, "Is this correct (Y or N)? ", inp2, "A");
readgets();
wclose(wno2);
if (inp2[0] == 'Y')
deg_chosen = 1;
else
deg_chosen = 0;
}
}
if (frac_mode == 1) { /* Get Julia-Set parameters */
while (!x_y_chosen) {
sprintf(title,"X, Y Maximum and Minimum Selection");
if ((wno2 = wxopen(6, 0, 16, 79,title,
ACTIVE+BORDER+BD2+SCROLL+CURSOR+CENTER,24,80)) == -1)
terror("set_plot(): Error opening X, Y Max & Min Selection window (WNO2)\n");
wselect(wno2);
erase();
empty(inp1, 80);
empty(inp2, 80);
empty(inp3, 80);
empty(inp4, 80);
atsayget(1, 0, "Enter X_MIN: ", inp1, "-#,###.##########");
atsayget(3, 0, "Enter X_MAX: ", inp2, "-#,###.##########");
atsayget(5, 0, "Enter Y_MIN: ", inp3, "-#,###.##########");
atsayget(7, 0, "Enter Y_MAX: ", inp4, "-#,###.##########");
readgets();
x_min = atof(inp1);
x_max = atof(inp2);
y_min = atof(inp3);
y_max = atof(inp4);
wclose(wno2); /* Close "X & Y-limits" Window */
if ((wno2 = wxopen(5,0,17,79,"Confirm (Y/N)",
ACTIVE+BORDER+BD2+SCROLL+CURSOR+CENTER, 20, 80)) == -1)
terror("set_plot(): Error opening X, Y Limits confirm window\n");
wselect(wno2);
woff();
atsay(0, 0, "The following are the X and Y limits chosen:");
sprintf(line, " X_MIN = %-15.10lf", x_min);
atsay(2, 0, line);
sprintf(line, " X_MAX = %-15.10lf", x_max);
atsay(4, 0, line);
sprintf(line, " Y_MIN = %-15.10lf", y_min);
atsay(6, 0, line);
sprintf(line, " Y_MAX = %-15.10lf", y_max);
atsay(8, 0, line);
won();
empty(line, 80);
atsayget(10, 0, "Are these correct (Y or N)? ", line, "A");
readgets();
if (line[0] == 'Y')
x_y_chosen = 1;
else
x_y_chosen = 0;
wclose(wno2); /* Close the "confirm" Window */
}
while (!p_q_chosen) {
sprintf(title,"P and Q Parameters Selection");
if ((wno2 = wxopen(7, 0, 13, 79,title,
ACTIVE+BORDER+BD2+SCROLL+CURSOR+CENTER,24,80)) == -1)
terror("set_plot(): Error opening P & Q Selection window (WNO2)\n");
wselect(wno2);
erase();
empty(inp1, 80);
empty(inp2, 80);
atsay(0, 0, "For the complex value C = P + iQ");
atsayget(2, 0, " Enter P: ", inp1, "-#,###.##########");
atsayget(4, 0, " Enter Q: ", inp2, "-#,###.##########");
readgets();
p = atof(inp1);
q = atof(inp2);
wclose(wno2); /* Close "P-Q Window */
if ((wno2 = wxopen(5,0,17,79,"Confirm (Y/N)",
ACTIVE+BORDER+BD2+SCROLL+CURSOR+CENTER, 20, 80)) == -1)
terror("set_plot(): Error opening P, Q value confirm window\n");
wselect(wno2);
woff();
atsay(0, 0, "For the equation C = P + iQ the values are:");
sprintf(line, " P = %-15.10lf", p);
atsay(2, 0, line);
sprintf(line, " Q = %-15.10lf", q);
atsay(4, 0, line);
won();
empty(line, 80);
atsayget(6,0,"Are these correct (Y or N)? ", line, "A");
readgets();
if (line[0] == 'Y')
p_q_chosen = 1;
else
p_q_chosen = 0;
wclose(wno2); /* Close "confirm" Window */
}
}
else if (frac_mode == 2) { /* Get Mendlebrot parameters */
while (!p_q_chosen) {
sprintf(title,"P, Q Maximum and Minimum Selection");
if ((wno2 = wxopen(6, 0, 16, 79,title,
ACTIVE+BORDER+BD2+SCROLL+CURSOR+CENTER,24,80)) == -1)
terror("set_plot(): Error opening P, Q Max & Min Selection window (WNO2)\n");
wselect(wno2);
erase();
empty(inp1, 80);
empty(inp2, 80);
empty(inp3, 80);
empty(inp4, 80);
atsayget(1, 0, "Enter P_MIN: ", inp1, "-#,###.##########");
atsayget(3, 0, "Enter P_MAX: ", inp2, "-#,###.##########");
atsayget(5, 0, "Enter Q_MIN: ", inp3, "-#,###.##########");
atsayget(7, 0, "Enter Q_MAX: ", inp4, "-#,###.##########");
readgets();
p_min = atof(inp1);
p_max = atof(inp2);
q_min = atof(inp3);
q_max = atof(inp4);
wclose(wno2); /* Close "P & Q-limits" Window */
if ((wno2 = wxopen(5,0,17,79,"Confirm (Y/N)",
ACTIVE+BORDER+BD2+SCROLL+CURSOR+CENTER, 20, 80)) == -1)
terror("set_plot(): Error opening P, Q Limits confirm window\n");
wselect(wno2);
woff();
atsay(0, 0, "The following are the P and Q limits chosen:");
sprintf(line, " P_MIN = %-15.10lf", p_min);
atsay(2, 0, line);
sprintf(line, " P_MAX = %-15.10lf", p_max);
atsay(4, 0, line);
sprintf(line, " Q_MIN = %-15.10lf", q_min);
atsay(6, 0, line);
sprintf(line, " Q_MAX = %-15.10lf", q_max);
atsay(8, 0, line);
won();
empty(line, 80);
atsayget(10, 0, "Are these correct (Y or N)? ", line, "A");
readgets();
if (line[0] == 'Y')
p_q_chosen = 1;
else
p_q_chosen = 0;
wclose(wno2); /* Close the "confirm" Window */
}
}
else {
sprintf(line, "set_plot(): Invalid FRAC_MODE value -- %d\n",frac_mode);
terror(line);
return;
}
while (!m_k_chosen) {
if ((wno2 = wxopen(5,0,13,79,"M & K parameter selection",
ACTIVE+BORDER+BD2+CURSOR+SCROLL+CENTER, 10, 80)) == -1)
terror("set_plot(): Error opening M & K parameter selection window\n");
wselect(wno2);
empty(inp1, 80);
empty(inp2, 80);
atsayget(0, 0, "Enter integer value for parameter M (suggest 100): ",
inp1, "#,###");
atsay(2, 0, "Enter integer number of colors K to use,");
atsayget(3, 0, " (suggest 200 even on CGA or EGA): ", inp2, "#,###");
readgets();
M = atoi(inp1);
K = atoi(inp2);
wclose(wno2);
if ((wno2 = wxopen(5,0,13,79,"Confirm (Y/N)",
ACTIVE+BORDER+BD2+CURSOR+SCROLL+CENTER, 10, 80)) == -1)
terror("set_plot(): Error opening M & K confirmation window.\n");
wselect(wno2);
woff();
atsay(0, 0, "The values for M and K are:");
sprintf(line, " M = %-4d", M);
atsay(2, 0, line);
sprintf(line, " K = %-4d", K);
atsay(4, 0, line);
won();
empty(line, 80);
atsayget(6, 0, "Is this correct (Y or N)? ", line, "A");
readgets();
if (line[0] == 'Y')
m_k_chosen = 1;
else
m_k_chosen = 0;
wclose(wno2);
}
while (!mode_chosen) {
if ((wno2 = wxopen(4,0,21,79,"Graphics Mode Selection",
ACTIVE+SCROLL+BORDER+CENTER+BD2+CURSOR,24, 80)) == -1)
terror("set_plot: Error opening Mode Selection window\n");
wselect(wno2);
woff();
atsay(0 , 0, "Which graphics mode do you wish:");
atsay(2 , 0, " 1 = 320 X 200, 4-colors");
atsay(4 , 0, " 2 = 640 X 200, Black/White");
atsay(6 , 0, " 3 = 320 X 200, 16-color");
atsay(8 , 0, " 4 = 640 X 200, 16-color");
atsay(10, 0, " 5 = 640 X 350, 16-color");
won();
empty(line, 80);
atsayget(12, 0, " Enter your choice (1, 2, 3, 4 or 5): ", line, "#");
readgets();
wclose(wno2);
USE_MODE = 0;
gr_m = atoi(line);
switch (gr_m) {
case 1:
USE_MODE = 4;
a = 320.0;
b = 200.0;
break;
case 2:
USE_MODE = 6;
a = 640.0;
b = 200.0;
break;
case 3:
USE_MODE = 13;
a = 320.0;
b = 200.0;
break;
case 4:
USE_MODE = 14;
a = 640.0;
b = 200.0;
break;
case 5:
USE_MODE = 16;
a = 640.0;
b = 350.0;
break;
}
if ((wno2 = wxopen(8,0,16,79,"Confirm (Y/N)",
CURSOR+BORDER+ACTIVE+BD2+CENTER+SCROLL, 10, 80)) == -1)
terror("set_plot(): Error opening resolution confirmation window\n");
wselect(wno2);
woff();
if (USE_MODE != 0) {
sprintf(line, "This plot will be done in %d X %d resolution",
(int)a, (int)b);
atsay(0, 0, line);
if (USE_MODE == 13 || USE_MODE == 14 || USE_MODE == 16)
atsay(1, 0, " (Requires EGA Card)");
empty(inp1, 80);
won();
atsayget(3, 0, "Is this correct (Y or N)? ", inp1, "A");
readgets();
if (inp1[0] == 'Y')
mode_chosen = 1;
else
mode_chosen = 0;
}
else {
sprintf(inp2, "Invalid USE_MODE assigned (%d) -- %d\n\"%s\"\n\n",
USE_MODE, gr_m, line);
terror (inp2);
}
wclose(wno2);
}
v_lin_max = (int)a - 1;
wclose(wno1);
} /* End of SET_PLOT */
void plot_fractal(fi_name, frac_mode)
char *fi_name;
int frac_mode;
{
register int k;
int i, ii, ij, j, save_mode, che, he_che, save_backg, get_che, ideg;
int gr_stuf[3];
double xy_stuf[4];
char line[80], *li_result;
ideg = build_fctn(degree); /* Generate polynomial vectors */
h_lin_count = 0;
mycolor = 0;
PALETTE = 1; /* Default is PALETTE = 0 */
get_mode(); /* Save the current display stats */
save_mode = CURRENT_MODE;
set_mode(USE_MODE); /* Turn on selected graphics mode */
if (USE_MODE == 4 || USE_MODE == 5) {
set_palette(PALETTE);
set_background(BACKGROUND);
}
if (frac_mode == 1) {
delt_x = (x_max - x_min) / (a - 1);
delt_y = (y_max - y_min) / (b - 1);
c = p + q;
}
else if (frac_mode == 2) {
delt_p = (p_max - p_min) / (a - 1);
delt_q = (q_max - q_min) / (b - 1);
}
/* Now the work begins */
/* Step 1 */
for (n_x=0;n_x<a;n_x++) {
for (n_y=0;n_y<b;n_y++) {
k = 0;
if (frac_mode == 1) {
x[k] = x_min + (n_x * delt_x);
y[k] = y_min + (n_y * delt_y);
}
else if (frac_mode == 2) {
x[0] = 0;
y[0] = 0;
p = p_min + (n_x * delt_p);
q = q_min + (n_y * delt_q);
}
/* Step 2 (Iteration step) */
do {
x[k+1] = calc_nx(x[k],y[k]); /* Feedback for next x using
vectors generated by the
function "build_fctn(int)" */
y[k+1] = calc_ny(x[k],y[k]); /* Feedback for next y using
vectors generated by the
function "build_fctn(int)" */
k++;
/* Step 3 (Evaluation step) */
r = (x[k] * x[k]) + (y[k] * y[k]);
} while (r <= M && k < K);
/* Step 4 */
if (k == K)
mycolor = 0;
else {
if (USE_MODE == 6 || USE_MODE == 5)
mycolor = 1; /* Black or White for 640*200 */
else if (USE_MODE == 13 || USE_MODE ==14 || USE_MODE == 16)
mycolor = (k % 15) + 1;
else if (USE_MODE == 4)
mycolor = (k % 3) + 1; /* Adjust for 4 color 320*200 */
}
plot_point(n_x,((b - 1) - n_y),mycolor); /* Plot point */
} /* Next n_y */
/*
After plotting each vertical line, check for something from the keyboard.
The following are valid, the rest are discarded.
<ESC> - Abort the current plot; do not save picture "as is".
Q - Quit the current plot; and save the picture "as is".
*/
if (kbhit()) {
get_che = getch();
if (get_che == 27) {
set_mode(save_mode);
return;
}
else if (get_che == 'q' || get_che == 'Q')
break;
}
} /* Next n_x */
/* Save the picture we just drew; then wait for a <CR> before continuing
or wait for a :
? - Display this menu
P - Change between color palette 0 and 1
B - Change background colors (from color 0 - 15)
D - Dump screen to printer (print plot)
C - Put a blank line on each odd numbered column.
H - Put a blank line on each odd numbered row (from the top down).
<CR>, <ESC> - Return to main menu
*/
gr_stuf[0] = a;
gr_stuf[1] = b;
gr_stuf[2] = USE_MODE;
if (frac_mode == 1){
xy_stuf[0] = x_min;
xy_stuf[1] = x_max;
xy_stuf[2] = y_min;
xy_stuf[3] = y_max;
}
else {
xy_stuf[0] = p_min;
xy_stuf[1] = p_max;
xy_stuf[2] = q_min;
xy_stuf[3] = q_max;
}
save_pic(fi_name,xy_stuf,gr_stuf);
do {
che = getone();
readgets();
switch (che) {
case '?':
wno2 = wxopen(5,20,17,58,"HELP",
ACTIVE+CURSOR+CENTER+BORDER+BD3, 24, 80);
wselect(wno2);
woff();
atsay(1,0," ? - Display this menu");
atsay(2,0," P - Change color palette");
atsay(3,0," B - Change background");
atsay(4,0," D - Print screen");
atsay(5,0," C - Blank line odd column.");
atsay(6,0," H - Put a black line every 5 lines ");
atsay(7,0," (from the top down)");
atsay(8,0," <CR>, <ESC> - Return to main menu");
atsay(9,0,"Press any key to exit");
won();
he_che = getone();
readgets();
wclose(wno2);
break;
case 'p':
case 'P':
if (PALETTE == 1)
PALETTE = 0;
else
PALETTE = 1;
if (USE_MODE == 4 || USE_MODE == 5)
set_palette(PALETTE);
break;
case 'b':
case 'B':
BACKGROUND++;
if (BACKGROUND > 15)
BACKGROUND = 0;
if (USE_MODE == 4 || USE_MODE == 5)
set_background(BACKGROUND);
break;
case 'd':
case 'D':
if (USE_MODE == 4 || USE_MODE == 5) {
save_backg = BACKGROUND;
BACKGROUND = 0;
set_background(BACKGROUND);
}
print_pic();
if (USE_MODE == 4 || USE_MODE == 5) {
BACKGROUND = save_backg;
set_background(BACKGROUND);
}
break;
case 'c':
case 'C':
if ((v_lin_count + 1) >= v_lin_max)
break;
v_lin_count++;
for (i=0;i<=b-1;i++)
plot_point(v_lin_count,i,0);
v_lin_count++;
break;
case 'h':
case 'H':
ii = 4;
while (ii<=b-1) {
for (ij=0;ij<=25;ij++)
plot_point(ij,ii,0);
ii+=5;
}
break;
}
} while (che != '\033' && che != '\012' && che != '\015');
set_mode(save_mode);
} /* End of PLOT_FRACTAL */
void restore_picture()
{
int i, ii, ij, j, k, fname_chosen, mo_chosen, save_mode, che, save_backg,
result, he_che, is_ega, max_row;
double d_i;
char line[80];
char *li_result, *fi_name;
h_lin_count = 0;
v_lin_count = 0;
fname_chosen = 0;
mo_chosen = 0;
is_ega = 0;
if ((wno1 = wxopen(0,0,24,79,"Restore Previous Plot",
ACTIVE+BORDER+BD1+CURSOR+CENTER, 24, 80)) == -1)
terror("restore_picture(): Error opening restore main window\n");
erase();
if ((wno2 = wxopen(8,0,12,79,"Plot Type",
ACTIVE+BORDER+BD2+CURSOR+CENTER, 10, 80)) == -1)
terror("restore_picture(): Error opening PLOT TYPE window\n");
wselect(wno2);
empty(line, 80);
atsayget(0,0,"Is this an EGA plot (Y or N)? ", line, "A");
if (line[0] == 'Y')
is_ega = 1;
else
is_ega = 0;
wclose(wno2);
while (!fname_chosen) {
if ((wno2 = wxopen(6,0,10,79, "Filename selection",
ACTIVE+BORDER+BD2+CURSOR+CENTER, 5, 80)) == -1)
terror("restore_picture(): Error opening file name selection window\n");
empty(fi_name, 80);
wselect(wno2);
atsayget(1, 0, "Enter filename to load: ", fi_name, "XXXXXXXX.XXX");
readgets();
wclose(wno2); /* Close "filename" Window */
wselect(wno1);
if (strlen(fi_name) == 0)
return; /* Return on only <CR> as a response */
/* Check to see if file specified exists, if not, complain */
result = stat(fi_name, &pic_buf);
if (result != 0) {
if ((wno2 = wxopen(20,0,24,79,"Error Message",
ACTIVE+BORDER+BD2+CENTER+CURSOR+SCROLL, 5, 80)) == -1)
terror("restore_picture(): Error opening error message window\n");
sprintf(line, "Error opening filename (%s)", fi_name);
atsay(0,0,line);
for (i=0;i<=3000;i++)
d_i = i * 1.01;
wclose(wno2); /* Close "error" Window */
wselect(wno1);
}
else {
if (pic_buf.st_size == 64038 ||
pic_buf.st_size == 128038 ||
pic_buf.st_size == 224038) {
fname_chosen = 1;
if (pic_buf.st_size == 64038 ||
pic_buf.st_size == 128038) {
v_lin_max = (int)(pic_buf.st_size / 200) - 1;
USE_MODE = 4;
if (v_lin_max == 639)
USE_MODE = 6;
max_row = 199;
}
else if (pic_buf.st_size == 224038) {
USE_MODE == 16;
v_lin_max = 639;
max_row = 349;
}
}
else {
if ((wno2 = wxopen(20,0,24,79,"Error Message",
ACTIVE+BORDER+BD2+CENTER+CURSOR+SCROLL, 5, 80)) == -1)
terror("restore_picture(): Error opening error message window\n");
wselect(wno2);
sprintf(line, "Improper filesize for file (%s)", fi_name);
atsay(0,0,line);
fname_chosen = 0;
for (i=0;i<=3000;i++)
d_i = i * 1.01;
wclose(wno2); /* Close "filesize error" Window */
wselect(wno1);
}
}
}
if (is_ega) {
if (USE_MODE == 4)
USE_MODE = 13;
else if (USE_MODE == 6)
USE_MODE == 14;
}
mo_chosen = USE_MODE;
mycolor = 0;
PALETTE = 1;
BACKGROUND = 0;
get_mode(); /* Save the current display stats */
save_mode = CURRENT_MODE;
set_mode(USE_MODE); /* Turn on appropriate graphics mode */
if (USE_MODE == 4 || USE_MODE == 5) {
set_palette(PALETTE); /* Select color palette */
set_background(BACKGROUND); /* Default to Black background */
}
load_pic(fi_name);
do {
che = getone();
switch (che) {
case '?':
wno2 = wxopen(5,20,17,58,"HELP",
ACTIVE+CURSOR+CENTER+BORDER+BD3, 24, 80);
wselect(wno2);
woff();
atsay(1,0," ? - Display this menu");
atsay(2,0," P - Change color palette");
atsay(3,0," B - Change background");
atsay(4,0," D - Print screen");
atsay(5,0," C - Blank line odd column.");
atsay(6,0," H - Put a black line every 5 lines ");
atsay(7,0," (from the top down)");
atsay(8,0," <CR>, <ESC> - Return to main menu");
atsay(9,0,"Press any key to exit");
won();
he_che = getone();
readgets();
wclose(wno2);
break;
case 'p':
case 'P':
if (PALETTE == 1)
PALETTE = 0;
else
PALETTE = 1;
if (USE_MODE == 4 || USE_MODE == 5)
set_palette(PALETTE);
break;
case 'b':
case 'B':
BACKGROUND++;
if (BACKGROUND > 15)
BACKGROUND = 0;
if (USE_MODE == 4 || USE_MODE == 5)
set_background(BACKGROUND);
break;
case 'd':
case 'D':
if (USE_MODE == 4 || USE_MODE == 5) {
save_backg = BACKGROUND;
BACKGROUND = 0;
set_background(BACKGROUND);
}
print_pic();
if (USE_MODE == 4 || USE_MODE == 5) {
BACKGROUND = save_backg;
set_background(BACKGROUND);
}
break;
case 'c':
case 'C':
if ((v_lin_count + 1) >= v_lin_max)
break;
v_lin_count++;
for (i=0;i<=b-1;i++)
plot_point(v_lin_count,i,0);
v_lin_count++;
break;
case 'h':
case 'H':
ii = 4;
while (ii<=b-1) {
for (ij=0;ij<=25;ij++)
plot_point(ij,ii,0);
ii+=5;
}
break;
}
} while (che != '\033' && che != '\012' && che != '\015');
set_mode(save_mode);
wclose(wno1);
} /* End of RESTORE_PICTURE */
long factorial(fac_num)
int fac_num;
{
register int i;
long f_ret;
if (fac_num <= 1)
return(1);
f_ret = 1;
for (i=1;i<=fac_num;i++)
f_ret *= ((long)i);
return(f_ret);
} /* End of FACTORIAL */
int build_fctn(degree)
int degree;
{
register int d_kount, k_adj, equ_loc;
equ_loc = 2;
konst[0] = 1;
/*
Initialize the first and last elements of the constant and exponent
arrays.
*/
real_exp[0] = degree;
imag_exp[0] = 0;
konst[degree] = 1;
real_exp[degree] = 0;
imag_exp[degree] = degree;
/*
Now loop through for each individual element of the equation we are
generating and calculate the constant, and exponent arrays.
*/
for (d_kount=1;d_kount<degree;d_kount++) {
konst[d_kount] = 1;
for (k_adj=0;k_adj<d_kount;k_adj++)
konst[d_kount] *= (degree - k_adj);
konst[d_kount] /= factorial(d_kount);
real_exp[d_kount] = degree - d_kount;
imag_exp[d_kount] = d_kount;
}
/*
Now adjust the sign(s) of the equation. It follows a "++--++--..."
pattern.
*/
do {
konst[equ_loc] *= -1;
if (equ_loc + 1 <= degree)
konst[equ_loc + 1] *= -1;
equ_loc += 4;
} while (equ_loc <= degree);
return(degree);
} /* End of BUILD_FCTN */
double calc_nx(old_x,old_y)
double old_x, old_y;
{
register int i;
double new_x, r_exp, i_exp, t_value;
new_x = 0.0;
for (i=0;i<=degree;i+=2) {
t_value = ((double)konst[i]) * pow_r(old_x, real_exp[i]);
t_value *= pow_r(old_y, imag_exp[i]);
new_x += t_value;
}
new_x += p;
return(new_x);
} /* End of CALC_NX */
double calc_ny(old_x, old_y)
double old_x, old_y;
{
register int i;
double new_y, r_exp, i_exp, t_value;
new_y = 0.0;
for (i=1;i<=degree;i+=2) {
t_value = ((double)konst[i]) * pow_r(old_x,real_exp[i]);
t_value *= pow_r(old_y, imag_exp[i]);
new_y += t_value;
}
new_y += q;
return(new_y);
} /* End of CALC_NY */
/*
For some reason the "pow(double,double)" function included in the
Microsoft 'C' 4.00 compiler conflicts with the graphics routines
in many cases. Thus the "pow_r(double,int)" function is designed
as a crude replacement for what we are doing.
*/
double pow_r(num_r, exp_t)
double num_r;
int exp_t;
{
register int i;
double temp_d;
if (exp_t == 0)
return(1.0);
temp_d = 1.0;
for (i=1;i<=exp_t;i++)
temp_d *= num_r;
return(temp_d);
} /* End of POW_R */